package com.easyCms.base.service;

import com.easyCms.base.common.CodeConst;
import com.easyCms.base.dao.AppIdentityDAO;
import com.easyCms.base.entity.AppIdentity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppIdentitySV {

    @Autowired
    private AppIdentityDAO appIdentityDAO;

    /**
     * 保存账号信息
     *
     * @param entity
     * @return
     */
    public AppIdentity save(AppIdentity entity) {
        return appIdentityDAO.save(entity);
    }

    /**
     * 根据账号名查询账号信息
     *
     * @param loginName
     * @return
     */
    public List<AppIdentity> findByLoginName(String loginName) {
        return appIdentityDAO.findByStateAndLoginName(CodeConst.State.STATE_VALID, loginName);
    }

    public AppIdentity findByIdAndState(Long id, int state) {
        return appIdentityDAO.findByIdAndState(id, state);
    }

    public AppIdentity findByHamiCode(String hamiCode) {
        return appIdentityDAO.findByHamiCodeAndState(hamiCode, CodeConst.State.STATE_VALID);
    }

}
